<%= header %>
<!--
Same test as 17-wait but calls SPA.markNavigationComplete instead of SPA.wait_complete
-->
<%= boomerangScript %>
<script src="support/function-bind-polyfill.js" type="text/javascript"></script>

<base href="/pages/12-react/117-wait.html" />

<script type="text/javascript">
window.imgs = [-1];
window.html5_mode = true;

//
// Routes:
// 1. Home page (hard nav) - Filter: n/a, (hard navs can't be filtered, doesn't wait)
// 2. Home page (soft nav) - Filter: true, takes: 5 seconds (fires after resource)
// 3. Home page (soft nav) - Filter: true, takes: 1 ms (fires before resource)
// 4. Home page (soft nav) - Filter: false (doesn't wait)
//
window.nav_routes = ["/widgets/1", "/widgets/2", ""];

// how long we should wait for each route
var routeWaits = [
	// spa_hard isn't filtered
	5000,
	1,
	0
];

// we'll put the end timestamps of each route in here so we can validate against beacons
window.spaWaitCompleteTimes = [];

// current route number
var routeNumber = 0;

// callback for each route
window.route_wait = function() {
	if (routeWaits[routeNumber]) {
		setTimeout(function() {
			window.spaWaitCompleteTimes.push(BOOMR.now());

			// call complete 5 seconds afterward route start
			BOOMR.plugins.SPA.markNavigationComplete();
		}, routeWaits[routeNumber]);

		// this will test that a history event issued while a routeChangeWaitFilter
		// is in progress will be ignored
		if (routeNumber === 1) {
			setTimeout(function() {
				history.state.foo = "bar";
				history.replaceState(history.state, document.title);  // update the state object
			}, 1000);
		}

		routeNumber++;

		return true;
	}
	else {
		// not waiting for this route
		return false;
	}
};
</script>


<div id="root"></div>
<div id="output"></div>

<script src="117-wait.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 4 : 1,
	History: {
		enabled: true
	},
	Errors: {
		enabled: false
	},
	instrument_xhr: true,
	autorun: false
});
</script>
<!-- start the app after config so that boomerang catches all requests and makes the test results the same as the other apps -->
<script src="support/app.js"></script>
<%= footer %>
